import { arrayRoutes, constantRoutes } from '@/router/index'

const state = {
    permRoutes: []
}

const mutations = {
    setRoutes(state, routes) {
        // 拼接常态路由
        state.permRoutes = [...constantRoutes, ...routes] //vuex保存动态路由
    }
}

const actions = {
    filterRoutes(context, menus) {
        const routes = arrayRoutes.filter(item => {
            return menus.includes(item.code) //返回匹配的权限路由
        })
        context.commit('setRoutes', routes)
        return routes
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}